<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  <html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<title>File Source for database_import.php</title>
	<link rel="stylesheet" type="text/css" href="../media/style.css">
	<meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1'/>
	<script src="media/a.js"></script>
</head>
<body>

<table border="0" cellspacing="0" cellpadding="0" height="48" width="100%">
  <tr>
	<td class="header-top-left"><img src="../media/logo.png" border="0" alt="phpDocumentor " /></td>
    <td class="header-top-right">Examples<br /><div class="header-top-right-subpackage"></div></td>
  </tr>
  <tr><td colspan="2" class="header-line"><img src="../media/empty.png" width="1" height="1" border="0" alt=""  /></td></tr>
  <tr>
    <td colspan="2" class="header-menu">
      
                                      
                                    		[ <a href="../classtrees_Examples.html" class="menu">class tree: Examples</a> ]
		[ <a href="../elementindex_Examples.html" class="menu">index: Examples</a> ]
            [ <a href="../elementindex.html" class="menu">all elements</a> ]
    </td>
  </tr>
  <tr><td colspan="2" class="header-line"><img src="../media/empty.png" width="1" height="1" border="0" alt=""  /></td></tr>
</table>

<table width="100%" border="0" cellpadding="0" cellspacing="0">
  <tr valign="top">
    <td width="195" class="menu">
		<div class="package-title">Examples</div>
  <div class="package">
	<div id="todolist">
			<p><a href="../todolist.html">Todo List</a></p>
	</div>
	</div>
      <b>Packages:</b><br />
  <div class="package">
              <a href="../li_QueryPath.html">QueryPath</a><br />
              <a href="../li_Examples.html">Examples</a><br />
              <a href="../li_Tests.html">Tests</a><br />
      	</div>
      <br />
                        <br />
                      </td>
    <td>
      <table cellpadding="10" cellspacing="0" width="100%" border="0"><tr><td valign="top">

<h1 align="center">Source for file database_import.php</h1>
<p>Documentation is available at <a href="../Examples/_examples---database_import.php.html">database_import.php</a></p>
<div class="src-code"><span class="php">
<ol><li><div class="src-line"><a name="a1"></a><span class="src-php">&lt;?php</span></div></li>
<li><div class="src-line"><a name="a2"></a><span class="src-doc">/**</span></div></li>
<li><div class="src-line"><a name="a3"></a><span class="src-doc">&nbsp;*&nbsp;Use&nbsp;QueryPath's&nbsp;database&nbsp;extension&nbsp;to&nbsp;import&nbsp;XML&nbsp;data&nbsp;into&nbsp;a&nbsp;database.</span></div></li>
<li><div class="src-line"><a name="a4"></a><span class="src-doc">&nbsp;*</span></div></li>
<li><div class="src-line"><a name="a5"></a><span class="src-doc">&nbsp;*&nbsp;</span><span class="src-doc-coretag">@package</span><span class="src-doc">&nbsp;Examples</span></div></li>
<li><div class="src-line"><a name="a6"></a><span class="src-doc">&nbsp;*&nbsp;</span><span class="src-doc-coretag">@author</span><span class="src-doc">&nbsp;M&nbsp;Butcher&nbsp;&lt;matt@aleph-null.tv&gt;</span></div></li>
<li><div class="src-line"><a name="a7"></a><span class="src-doc">&nbsp;*&nbsp;</span><span class="src-doc-coretag">@license</span><span class="src-doc">&nbsp;LGPL&nbsp;The&nbsp;GNU&nbsp;Lesser&nbsp;GPL&nbsp;(LGPL)&nbsp;or&nbsp;an&nbsp;MIT-like&nbsp;license.</span></div></li>
<li><div class="src-line"><a name="a8"></a><span class="src-doc">&nbsp;*/</span></div></li>
<li><div class="src-line"><a name="a9"></a>&nbsp;</div></li>
<li><div class="src-line"><a name="a10"></a><span class="src-inc">require_once&nbsp;</span><span class="src-str">'../src/QueryPath/QueryPath.php'</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a11"></a><span class="src-inc">require_once&nbsp;</span><span class="src-str">'../src/QueryPath/Extension/QPDB.php'</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a12"></a>&nbsp;</div></li>
<li><div class="src-line"><a name="a13"></a><span class="src-comm">//&nbsp;Set&nbsp;the&nbsp;default&nbsp;database.</span></div></li>
<li><div class="src-line"><a name="a14"></a><span class="src-id"><a href="../QueryPath/Extension/QPDB.html">QPDB</a></span><span class="src-sym">::</span><a href="../QueryPath/Extension/QPDB.html#methodbaseDB">baseDB</a><span class="src-sym">(</span><span class="src-str">'sqlite:../test/db/qpTest.db'</span><span class="src-sym">)</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a15"></a>&nbsp;</div></li>
<li><div class="src-line"><a name="a16"></a><span class="src-comm">//&nbsp;To&nbsp;begin,&nbsp;let's&nbsp;create&nbsp;a&nbsp;new&nbsp;database.&nbsp;We&nbsp;can&nbsp;do&nbsp;this&nbsp;outside</span></div></li>
<li><div class="src-line"><a name="a17"></a><span class="src-comm">//&nbsp;of&nbsp;QueryPath:</span></div></li>
<li><div class="src-line"><a name="a18"></a><span class="src-var">$db&nbsp;</span>=&nbsp;<span class="src-id"><a href="../QueryPath/Extension/QPDB.html">QPDB</a></span><span class="src-sym">::</span><a href="../QueryPath/Extension/QPDB.html#methodgetBaseDB">getBaseDB</a><span class="src-sym">(</span><span class="src-sym">)</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a19"></a><span class="src-var">$db</span><span class="src-sym">-&gt;</span><a href="http://www.php.net/exec">exec</a><span class="src-sym">(</span><span class="src-str">'CREATE&nbsp;TABLE&nbsp;IF&nbsp;NOT&nbsp;EXISTS&nbsp;qpdb_article&nbsp;(title,&nbsp;author,&nbsp;body)'</span><span class="src-sym">)</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a20"></a>&nbsp;</div></li>
<li><div class="src-line"><a name="a21"></a><span class="src-comm">//&nbsp;Here's&nbsp;our&nbsp;sample&nbsp;article:</span></div></li>
<li><div class="src-line"><a name="a22"></a><span class="src-var">$article&nbsp;</span>=&nbsp;<span class="src-str">'&lt;?xml&nbsp;version=&quot;1.0&quot;?&gt;</span></div></li>
<li><div class="src-line"><a name="a23"></a><span class="src-str">&lt;article&gt;</span></div></li>
<li><div class="src-line"><a name="a24"></a><span class="src-str">&nbsp;&nbsp;&lt;title&gt;Use&nbsp;QueryPath&nbsp;for&nbsp;Fun&nbsp;and&nbsp;Profit&lt;/title&gt;</span></div></li>
<li><div class="src-line"><a name="a25"></a><span class="src-str">&nbsp;&nbsp;&lt;author&gt;</span></div></li>
<li><div class="src-line"><a name="a26"></a><span class="src-str">&nbsp;&nbsp;&nbsp;&nbsp;&lt;first&gt;Matt&lt;/first&gt;</span></div></li>
<li><div class="src-line"><a name="a27"></a><span class="src-str">&nbsp;&nbsp;&nbsp;&nbsp;&lt;last&gt;Butcher&lt;/last&gt;</span></div></li>
<li><div class="src-line"><a name="a28"></a><span class="src-str">&nbsp;&nbsp;&lt;/author&gt;</span></div></li>
<li><div class="src-line"><a name="a29"></a><span class="src-str">&nbsp;&nbsp;&lt;body&gt;</span></div></li>
<li><div class="src-line"><a name="a30"></a><span class="src-str">&nbsp;&nbsp;&lt;![CDATA[</span></div></li>
<li><div class="src-line"><a name="a31"></a><span class="src-str">&nbsp;&nbsp;&lt;p&gt;QueryPath&nbsp;is&nbsp;a&nbsp;great&nbsp;tool.&lt;/p&gt;</span></div></li>
<li><div class="src-line"><a name="a32"></a><span class="src-str">&nbsp;&nbsp;&lt;p&gt;Use&nbsp;it&nbsp;in&nbsp;many&nbsp;ways.&lt;/p&gt;</span></div></li>
<li><div class="src-line"><a name="a33"></a><span class="src-str">&nbsp;&nbsp;]]&gt;</span></div></li>
<li><div class="src-line"><a name="a34"></a><span class="src-str">&nbsp;&nbsp;&lt;/body&gt;</span></div></li>
<li><div class="src-line"><a name="a35"></a><span class="src-str">&lt;/article&gt;'</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a36"></a>&nbsp;</div></li>
<li><div class="src-line"><a name="a37"></a><span class="src-comm">//&nbsp;Now&nbsp;let's&nbsp;take&nbsp;this&nbsp;article&nbsp;and&nbsp;insert&nbsp;it&nbsp;into&nbsp;the&nbsp;database:</span></div></li>
<li><div class="src-line"><a name="a38"></a><span class="src-var">$qp&nbsp;</span>=&nbsp;<a href="../QueryPath/_src---QueryPath---QueryPath.php.html#functionqp">qp</a><span class="src-sym">(</span><span class="src-var">$article</span><span class="src-sym">)</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a39"></a>&nbsp;</div></li>
<li><div class="src-line"><a name="a40"></a><span class="src-comm">//&nbsp;We&nbsp;are&nbsp;going&nbsp;to&nbsp;store&nbsp;our&nbsp;insert&nbsp;params&nbsp;in&nbsp;here.</span></div></li>
<li><div class="src-line"><a name="a41"></a><span class="src-var">$params&nbsp;</span>=&nbsp;<span class="src-key">array</span><span class="src-sym">(</span><span class="src-sym">)</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a42"></a>&nbsp;</div></li>
<li><div class="src-line"><a name="a43"></a><span class="src-comm">//&nbsp;First,&nbsp;let's&nbsp;get&nbsp;the&nbsp;title</span></div></li>
<li><div class="src-line"><a name="a44"></a><span class="src-var">$params</span><span class="src-sym">[</span><span class="src-str">':title'</span><span class="src-sym">]&nbsp;</span>=&nbsp;<span class="src-var">$qp</span><span class="src-sym">-&gt;</span><span class="src-id">find</span><span class="src-sym">(</span><span class="src-str">'title'</span><span class="src-sym">)</span><span class="src-sym">-&gt;</span><span class="src-id">text</span><span class="src-sym">(</span><span class="src-sym">)</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a45"></a>&nbsp;</div></li>
<li><div class="src-line"><a name="a46"></a><span class="src-comm">//&nbsp;Next,&nbsp;let's&nbsp;get&nbsp;the&nbsp;name:</span></div></li>
<li><div class="src-line"><a name="a47"></a><span class="src-var">$params</span><span class="src-sym">[</span><span class="src-str">':name'</span><span class="src-sym">]&nbsp;</span>=&nbsp;<span class="src-var">$qp</span><span class="src-sym">-&gt;</span><span class="src-id">top</span><span class="src-sym">(</span><span class="src-sym">)</span><span class="src-sym">-&gt;</span><span class="src-id">find</span><span class="src-sym">(</span><span class="src-str">'author&gt;last'</span><span class="src-sym">)</span><span class="src-sym">-&gt;</span><span class="src-id">text</span><span class="src-sym">(</span><span class="src-sym">)&nbsp;</span>.&nbsp;<span class="src-str">',&nbsp;'&nbsp;</span>.&nbsp;<span class="src-var">$qp</span><span class="src-sym">-&gt;</span><a href="http://www.php.net/prev">prev</a><span class="src-sym">(</span><span class="src-str">'first'</span><span class="src-sym">)</span><span class="src-sym">-&gt;</span><span class="src-id">text</span><span class="src-sym">(</span><span class="src-sym">)</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a48"></a>&nbsp;</div></li>
<li><div class="src-line"><a name="a49"></a><span class="src-comm">//&nbsp;Finally,&nbsp;let's&nbsp;get&nbsp;the&nbsp;article&nbsp;content:</span></div></li>
<li><div class="src-line"><a name="a50"></a><span class="src-var">$params</span><span class="src-sym">[</span><span class="src-str">':body'</span><span class="src-sym">]&nbsp;</span>=&nbsp;<span class="src-var">$qp</span><span class="src-sym">-&gt;</span><span class="src-id">top</span><span class="src-sym">(</span><span class="src-sym">)</span><span class="src-sym">-&gt;</span><span class="src-id">find</span><span class="src-sym">(</span><span class="src-str">'body'</span><span class="src-sym">)</span><span class="src-sym">-&gt;</span><span class="src-id">text</span><span class="src-sym">(</span><span class="src-sym">)</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a51"></a>&nbsp;</div></li>
<li><div class="src-line"><a name="a52"></a><span class="src-comm">//&nbsp;Here's&nbsp;the&nbsp;query&nbsp;we&nbsp;are&nbsp;going&nbsp;to&nbsp;run:</span></div></li>
<li><div class="src-line"><a name="a53"></a><span class="src-var">$sql&nbsp;</span>=&nbsp;<span class="src-str">'INSERT&nbsp;INTO&nbsp;qpdb_article&nbsp;(title,&nbsp;author,&nbsp;body)&nbsp;VALUES&nbsp;(:title,&nbsp;:name,&nbsp;:body)'</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a54"></a>&nbsp;</div></li>
<li><div class="src-line"><a name="a55"></a><span class="src-comm">//&nbsp;Now&nbsp;we&nbsp;can&nbsp;insert&nbsp;this:</span></div></li>
<li><div class="src-line"><a name="a56"></a><span class="src-var">$qp</span><span class="src-sym">-&gt;</span><span class="src-id">query</span><span class="src-sym">(</span><span class="src-var">$sql</span><span class="src-sym">,&nbsp;</span><span class="src-var">$params</span><span class="src-sym">)</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a57"></a>&nbsp;</div></li>
<li><div class="src-line"><a name="a58"></a><span class="src-comm">//&nbsp;Finally,&nbsp;we&nbsp;can&nbsp;now&nbsp;read&nbsp;this&nbsp;information&nbsp;back&nbsp;out&nbsp;into&nbsp;an&nbsp;HTML&nbsp;document</span></div></li>
<li><div class="src-line"><a name="a59"></a><a href="../QueryPath/_src---QueryPath---QueryPath.php.html#functionqp">qp</a><span class="src-sym">(</span><span class="src-id"><a href="../QueryPath/QueryPath.html">QueryPath</a></span><span class="src-sym">::</span><span class="src-id">HTML_STUB</span><span class="src-sym">,&nbsp;</span><span class="src-str">'body'</span><span class="src-sym">)</span><span class="src-sym">-&gt;</span><span class="src-id">queryInto</span><span class="src-sym">(</span><span class="src-str">'SELECT&nbsp;*&nbsp;FROM&nbsp;qpdb_article'</span><span class="src-sym">)</span><span class="src-sym">-&gt;</span><span class="src-id">writeHTML</span><span class="src-sym">(</span><span class="src-sym">)</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a60"></a>&nbsp;</div></li>
<li><div class="src-line"><a name="a61"></a><span class="src-comm">//&nbsp;Finally,&nbsp;we&nbsp;clean&nbsp;up:</span></div></li>
<li><div class="src-line"><a name="a62"></a><span class="src-var">$qp</span><span class="src-sym">-&gt;</span><a href="http://www.php.net/exec">exec</a><span class="src-sym">(</span><span class="src-str">'DROP&nbsp;TABLE&nbsp;qpdb_article'</span><span class="src-sym">)</span><span class="src-sym">;</span></div></li>
</ol>
</span></div>
        <div class="credit">
		    <hr class="separator" />
		    Documentation generated on Thu, 19 Mar 2009 18:01:09 -0500 by <a href="http://www.phpdoc.org">phpDocumentor 1.4.2</a>
	      </div>
      </td></tr></table>
    </td>
  </tr>
</table>

</body>
</html>